using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
namespace Foundry.Engine
{
	public class Scene : Node
	{
		[NonSerialized]
		internal LinkedList<BaseObject> linear_array;
		
	
		public BaseObject FindObjectByHandle(int handle)
		{
			return linear_array.FirstOrDefault(item => item.Handle == handle);
		}
		
	
		[NonSerialized]
		private volatile int counter;
		
		[NonSerialized]
		private System.Threading.Mutex count_mutex;
		
		/// <summary>
		/// Generates an incremental index 
		/// </summary>
		/// <returns>
		/// An incremental number
		/// </returns>
		internal int GetCounter()
		{
			if(count_mutex == null)
				count_mutex = new System.Threading.Mutex();
			//count_mutex.WaitOne();
			int ret = ++counter;
			//count_mutex.ReleaseMutex();
			return ret;
		}
		
		private App owner;
		public App Owner { get { return owner; } private set { owner =value; } }
		
		public Scene (App owner)
		{
			Scene = this;
			linear_array = new LinkedList<Foundry.Engine.BaseObject>();
			//count_mutex = new System.Threading.Mutex();
			this.owner = owner;
		}
	}
}

